
<div class="index-content layui-main"> 
</div>
<style>
</style>

<script> 
  layui.use(['admin', 'form', 'user', 'laytpl'], function(){
    var $ = layui.$
    ,setter = layui.setter
    ,admin = layui.admin
    ,form = layui.form
    ,router = layui.router()
	,search = router.search
    laytpl = layui.laytpl;
    
    if(search.user_code && !search.app_id) { //不存在app_id跳转到homeindex
        var usercode = search.user_code.split('&')[0];
        admin.req({
            url: 'myapi/DC/loginByCode',
            data: {
                user_code: usercode
            },
            success:function(res) {
                if(res.retcode == 0){
                    layui.data(setter.tableName, {
                        key: setter.request.tokenName
                        ,value: res.jsonId
                    });
                    layui.data('userdata', {
                        key: 'data',
                        value: res.data
                    });
                    //登入成功的提示与跳转
                    layer.msg('登入成功', {
                        offset: '15px' 
                        ,icon: 1
                        ,time: 1000
                    }, function(){
                        location.hash = '/user/homeIndex';
                    });
                }
            }
        })
    }else if(search.app_id && search.user_code){ //都存在跳转到主页
        var appid = search.app_id.split('?')[0];
        admin.req({
            url: 'myapi/DC/loginByCode',
            data: {
                user_code: search.user_code
            },
            success:function(res) {
                if(res.retcode == 0){
                    layui.data(setter.tableName, {
                        key: setter.request.tokenName
                        ,value: res.jsonId
                    });
                    //请求成功写入用户信息
                    layui.data('userdata', {
                        key: 'data',
                        value: res.data
                    });

                    //登入成功的提示与跳转
                    layer.msg('登入成功', {
                        offset: '15px' 
                        ,icon: 1
                        ,time: 1000
                    }, function(){
                        admin.req({
                            type:"post",
                            url: 'myapi/DC/api/rest/web/custom/setApp',
                            data: {
                                app_id: appid
                            },
                            success: function(res){
                                if(res.retcode === '0') {
                                    // location.hash = '/more=1';
                                    location.hash = '/app_id='+appid;
                                }
                            }
                        })
                    });
                }
            }
        });
    }

  });
</script>